package pageobject;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class Page {

	protected WebDriver driver;
	protected String baseUrl;

	public Page(WebDriver driver) {
		super();
		this.driver = driver;
	}

	protected void insertText(By by, String text) {
		WebElement element = driver.findElement(by);
		element.clear();
		element.sendKeys(text);
	}

	protected void open(String url) {
		driver.get(url);
	}

	protected void click(By by) {
		driver.findElement(by).click();
	}

	protected void assertLinkTextEquals(String expectedText) {
		assertEquals(expectedText, driver
				.findElement(By.linkText(expectedText)).getText());
	}

	protected void assertTextPresent(String expectedText) {
		assertTrue(driver.getPageSource().contains(expectedText));
	}

	protected boolean isTextPresent(String expectedText) {
		return driver.getPageSource().contains(expectedText);
	}

	protected void logout(){
		click(By.linkText("Logout"));
	}
	
}